
// import * as d3 from "../lib/d3.js";
import * as d3 from "d3";
import {defineHandleButton} from "./buttons.js";
import {$} from "../util/seq.js";
import {gaEvent} from "../util/ga.js";
import {isIFrameContext, isKioskContext} from "../util/context.js";

/**
 * @param container
 * @param {Handle} show_cta
 */
export function defineCallToAction(container, show_cta) {
    const closeButton = container.select("button");

    function updateDOM() {
        container.property("hidden", !show_cta.get() || isKioskContext());
    }

    d3.selectAll(".cta-content").select("a")
        .attr("target", isIFrameContext() ? "_new" : null)
        .on($`click`, () => gaEvent("cta", "click"))
        .on($`contextmenu`, () => gaEvent("cta", "right-click"));

    show_cta.on($`change`, updateDOM);
    defineHandleButton(closeButton, show_cta, false);
}
